const express = require("express");

const cookieParser = require("cookie-parser");

var app = express();

//设置中间件

app.use(cookieParser());

app.get("/", function (req, res) {

    res.send("首页");

});

//设置cookie

app.get("/set", function (req, res) {

    res.cookie("userName", '张三', { maxAge: 200000, httpOnly: true, domain: "ccc.com" });

    res.send("设置cookie成功");

});

//获取cookie

app.get("/get", function (req, res) {

    console.log(req.cookies.userName);

    res.send("获取cookie成功，cookie为：" + req.cookies.userName);

});

app.listen(8080);

